/**
 * 用于页面级别的JS
 * wolfer
 * wolfers@126.com
 * 2013-04-10
 */

define(["js/mCard.js","js/mCommon.js"],function(card,common){  
	
	var Rank = {
			
			init:function(n){
				this.beanfun();
				$("#rank-dou").show();
				$("#rank-star").hide();
				$("#rank-candy").hide();
			},
			//财富排行
			//rank/tops/beanfun
			beanfun:function(){
				var _t = this;
				var url = Game.getBaseURL() + "/rank/tops/beanfun";
				$.ajax({
					url: url,
					dataType:"json",
					success: function(data){
						if(data.success){
							 var listsArr = data.data.tops;
							 console.log(listsArr);
							 _t.beanfunLists(listsArr);
						}else{
							$().alert({
								content : data.msgs.join("<br/>")
							});
						}
					}
				});
			},
			
			beanfunLists:function(data){
				var trArr = [];
				for(var i=0;i<data.length; i++){
					trArr.push("<tr class='table_line'>"+
					    "<td style='width:20%'>"+(i+1)+"</td>"+
					    "<td style='width:40%'>"+data[i].nickName+"</td>"+
					    "<td style='width:40%' >"+data[i].beanfun+"</td>"+
					  "</tr>");
				}
				$("#rankTable table").html(trArr.join(""));
			
			},
			
			//星星糖果排行
			//rank/tops/star-candy    
			star:function(){
				var _t = this;
				var url = Game.getBaseURL() + "/rank/tops/star-candy";
				$.ajax({
					url: url,
					dataType:"json",
					success: function(data){
						if(data.success){
							 var listsArr = data.data.tops;
							 _t.starLists(listsArr);
						}else{
							$().alert({
								content : data.msgs.join("<br/>")
							});
						}
					}
				});
			},
			
			starLists:function(data){
				var trArr = [];
				for(var i=0;i<data.length; i++){
					if(i===0){
						var r = "<span class='rank-icon-box'><span class='icon icon_no1 rank-icon'></span></span>";
					}else if(i===1){
						var r = "<span class='rank-icon-box'><span class='icon icon_no2 rank-icon'></span></span>";
					}else if(i===2){
						var r = "<span class='rank-icon-box'><span class='icon icon_no3 rank-icon'></span></span>";
					}else{
						var r = i+1;
					}
					trArr.push("<tr>"+
					    "<td style='width:20%'>"+r+"</td>"+
					    "<td style='width:40%'>"+data[i].nickName+"</td>"+
					    "<td style='width:20%' class='rankRight'><span class='rank-icon-box'><span class='icon t-4 icon_xing rank-small rank-icon'></span></span>"+data[i].star+"</td>"+
					    "<td style='width:20%' class='rankRight'><span class='rank-icon-box'><span class='icon t-4 icon_tang rank-small rank-icon'></span></span>"+data[i].candy+"</td>"+
					  "</tr>");
				}
				$("#rankTable table").html(trArr.join(""));
				this.oddTr();
			},
			
			//当局排行
			//rank/tops/round/beanfun   每局乐豆结算排行
			nowRank:function(){
				var _t = this;
				var url = Game.getBaseURL() + "/rank/tops/round/beanfun";
				$.ajax({
					url: url,
					dataType:"json",
					success: function(data){
						if(data.success){
							 var listsArr = data.data.tops;
							 _t.nowRankLists(listsArr);
						}else{
							$().alert({
								content : data.msgs.join("<br/>")
							});
						}
					}
				});
			},
			
			nowRankLists:function(data){
				var trArr = [];
				for(var i=0;i<data.length; i++){
					if(i===0){
						var r = "<span class='rank-icon-box'><span class='icon icon_no1 rank-icon'></span></span>";
					}else if(i===1){
						var r = "<span class='rank-icon-box'><span class='icon icon_no2 rank-icon'></span></span>";
					}else if(i===2){
						var r = "<span class='rank-icon-box'><span class='icon icon_no3 rank-icon'></span></span>";
					}else{
						var r = i+1;
					}
					trArr.push("<tr>"+
					    "<td style='width:20%'>"+r+"</td>"+
					    "<td style='width:40%'>"+data[i].nickName+"</td>"+
					    "<td style='width:40%'><span class='rank-icon-box'><span class='icon icon_dou_small  rank-icon'></span></span>"+data[i].beanfun+"</td>"+
					  "</tr>");
				}
				$("#rankTable table").html(trArr.join(""));
				this.oddTr();
			},
			
			oddTr:function(){
				var tr = $("#rankTable tr");
				for(var i=0;i<tr.length; i++){
					if(i%2 ===0){
						tr.eq(i).css("background","#e6c3bd");
					}
				}
			}
	};
	
	

	return {
		rank:function(n){
			Rank.init(n);
			
			var boss_return = $("#return");
			boss_return.live(common.getEvent[0],function(){
	    		$(this).addClass("on");
	    	});
			boss_return.live(common.getEvent[1],function(){
	    		$(this).removeClass("on");
	    		window.history.go(-1);
	    	});
		}
	}
		

}); 